<!DOCTYPE html>
<html>

  <head>
    <meta charset="UTF-8">
    <title>游戏列表</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/static/super_cmdb/css/font.css">
    <link rel="stylesheet" href="/static/super_cmdb/css/xadmin.css">

    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
      <style>
          .hide{
            display: none;
          }
      </style>
  </head>

  <body class="layui-anim layui-anim-up">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">用户列表</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="/super_cmdb/gameserver_list/" title="刷新">
        <i class="layui-icon" style="line-height:33px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row" style="width: 151px;position: relative"></div>
      <xblock>
          <li class="layui-nav-item">
            <form method="post" id="myform" onchange="submitForm()">
                {% csrf_token %}
                <select id="" name="gameserver_group_id" style="height: 30px;border: 0;width: 200px">
                    <option value="" id="blink">{{ select_group_name }}</option>
                    {% for gameserver_group in gameserver_group_list %}
                        <option value="{{ gameserver_group.id }}">{{ gameserver_group.group_name }}</option>
                    {% endfor %}
                </select>
            </form>
          </li>
      </xblock>

      <xblock>
          <form action="/super_cmdb/gameserver_list/" method="post" id="gameserver_filter" onchange="submitForm_gameserver_filter()">
              {% csrf_token %}
              <input style="width: 350px;height: 30px;border-radius: 7px;border: 0px;background-color: #e2e2f5;" placeholder="Filter: server_id |服务器名称 |目录名称 |server_ip" name="gameserver_filter" value="{{ gameserver_filter }}" onchange="submitForm();" >
          </form>
      </xblock>

      <xblock>
          <span style="color: green"><span style="color: red">注意: </span>以下操作按钮需要在[配置管理]-->[脚本配置]中配置脚本类型后,才可以使用 <span style="color: red">【同一项目下不可存在重复的server_id】</span></span>
      </xblock>



      <xblock>
          <button class="layui-btn" onclick="x_admin_show('平台部署新服','/super_cmdb/install_game-{{ project_id }}/',1000,700)"><i class="layui-icon"></i>平台部署新服</button>
          <button class="layui-btn" style="background-color: #a29a30;" onclick="x_admin_show('导入游戏服','/super_cmdb/import_gameserver/',1000,700)">导入游戏服</button>
          <a class="layui-btn" style="background-color: #a29a30;" href="/super_cmdb/gameserver_list/?filter_son_gameserver=yes&gameserver_group_id_filter={{ gameserver_group_id_filter }}" title="隐藏子服">隐藏子服</a>
          <button class="layui-btn" style="background-color: #259cbd" onclick="remove_hide_i11()">批量操作服务器</button>
{#          <button class="layui-btn" onclick="remove_hide_i3()">批量停服</button>#}
{#          <button class="layui-btn" onclick="remove_hide_i4()">批量备份</button>#}
          <button class="layui-btn" onclick="remove_hide_i5()">批量更新</button>
{#          <button class="layui-btn" onclick="remove_hide_i6()">批量限开</button>#}
{#          <button class="layui-btn" onclick="remove_hide_i7()">批量启动</button>#}
          <button class="layui-btn" onclick="remove_hide_i9()">一键更新</button>
          <button class="layui-btn" onclick="remove_hide_i10()">跨服连接配置</button>
{#          <button class="layui-btn" style="background-color: #a2268e;" onclick="x_admin_show('监听后，可以展示执行过程实时日志','/webssh/tailf/',1300,700)">实时日志</button>#}
          <button class="layui-btn layui-btn-danger" onclick="remove_hide_i8()">批量清档</button>
          <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
          <button class="layui-btn" onclick="exportCSV()"><i class="iconfont" style="font-size: 12px;">&#xe714;</i> 导出csv</button>
          <span class="x-right" style="line-height:40px">共有游戏服：{{ game_number }} 个</span>
      </xblock>

    <!-- 遮罩层部分start -->
    <div id="i2" class="hide"></div>
    <!-- 遮罩层部分end -->

    <!-- 弹出框部分start i3 -->
    <div id="i3" class="hide">
        <div style="padding-top: 30px;color: green;font-size: 20px;padding-bottom: 20px;">
            <span>批量停服操作</span>
        </div>
        <div class="layui-form-item">
              <label for="auth_type" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>选择执行认证方式
              </label>
              <div class="layui-input-inline">
                  <select id="auth_type3" name="auth_type3" style="height: 38px">
                        {% for auth_type in auth_type_list %}
                            <option value="{{ auth_type.auth_type }}">{{ auth_type.auth_type }}</option>
                        {% endfor %}
                  </select>
              </div>
        </div>
        <div class="layui-form-item">
              <label for="login_user" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>用户
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="login_user3" name="login_user3" required="" lay-verify="login_user" value="root"
                  autocomplete="off" class="layui-input">
              </div>
       </div>
        <div class="layui-form-item">
              <label for="password" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="password3" name="password3" required="" lay-verify="password" value=""
                  autocomplete="off" class="layui-input">
              </div>
       </div>
        <button class="layui-btn" onclick="StopAll()">开始停服</button>
        <button class="layui-btn" onclick="add_hide_i3()">取消</button>
    </div>
    <!-- 弹出框部分end i3-->

    <!-- 弹出框部分start i4 -->
    <div id="i4" class="hide">
        <div style="padding-top: 30px;color: green;font-size: 20px;padding-bottom: 20px;">
            <span>批量备份操作</span>
        </div>
        <div class="layui-form-item">
              <label for="auth_type" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>选择执行认证方式
              </label>
              <div class="layui-input-inline">
                  <select id="auth_type4" name="auth_type4" style="height: 38px">
                        {% for auth_type in auth_type_list %}
                            <option value="{{ auth_type.auth_type }}">{{ auth_type.auth_type }}</option>
                        {% endfor %}
                  </select>
              </div>
        </div>
        <div class="layui-form-item">
              <label for="login_user" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>用户
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="login_user4" name="login_user4" required="" lay-verify="login_user" value="root"
                  autocomplete="off" class="layui-input">
              </div>
        </div>
        <div class="layui-form-item">
              <label for="password" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="password4" name="password4" required="" lay-verify="password" value=""
                  autocomplete="off" class="layui-input">
              </div>
        </div>
        <button class="layui-btn" onclick="BackupAll()">开始备份</button>
        <button class="layui-btn" onclick="add_hide_i4()">取消</button>
    </div>
    <!-- 弹出框部分end i4-->

    <!-- 弹出框部分start i5 -->
    <div id="i5" class="hide">
        <div style="padding-top: 30px;color: green;font-size: 20px;padding-bottom: 20px;">
            <span>批量更新操作[更新脚本需要定义两个参数,更新包 和 版本号]</span>
        </div>
        <div class="layui-form-item">
              <label for="version_package" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>选择更新包
              </label>
              <div class="layui-input-inline" style="width: 480px;">
                  <select id="version_package5" name="version_package5" style="height: 38px">
                        {% for version_package in version_list %}
                            <option value="{{ version_package }}">{{ version_package }}</option>
                        {% endfor %}
                  </select>
              </div>
        </div>
{#        <div class="layui-form-item">#}
{#              <label for="svn_version" class="layui-form-label" style="width: 120px">#}
{#                  <span class="x-red">*</span>输入校验版本号#}
{#              </label>#}
{#              <div class="layui-input-inline">#}
{#                  <input type="text" id="svn_version5" name="svn_version5" required="" lay-verify="svn_version" placeholder="2363M_2373M"#}
{#                  autocomplete="off" class="layui-input">#}
{#              </div>#}
{#        </div>#}
        <div class="layui-form-item">
              <label for="auth_type" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>选择执行认证方式
              </label>
              <div class="layui-input-inline">
                  <select id="auth_type5" name="auth_type5" style="height: 38px">
                        {% for auth_type in auth_type_list %}
                            <option value="{{ auth_type.auth_type }}">{{ auth_type.auth_type }}</option>
                        {% endfor %}
                  </select>
              </div>
        </div>
        <div class="layui-form-item">
              <label for="login_user" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>用户
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="login_user5" name="login_user5" required="" lay-verify="login_user" value="root"
                  autocomplete="off" class="layui-input">
              </div>
        </div>
        <div class="layui-form-item">
              <label for="password" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="password5" name="password5" required="" lay-verify="password" value=""
                  autocomplete="off" class="layui-input">
              </div>
        </div>
        <button class="layui-btn" onclick="UpdateAll()">开始更新</button>
        <button class="layui-btn" onclick="add_hide_i5()">取消</button>
    </div>
    <!-- 弹出框部分end i5-->

    <!-- 弹出框部分start i6 -->
    <div id="i6" class="hide">
        <div style="padding-top: 30px;color: green;font-size: 20px;padding-bottom: 20px;">
            <span>批量限开操作</span>
        </div>
        <div class="layui-form-item">
              <label for="auth_type" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>选择执行认证方式
              </label>
              <div class="layui-input-inline">
                  <select id="auth_type6" name="auth_type6" style="height: 38px">
                        {% for auth_type in auth_type_list %}
                            <option value="{{ auth_type.auth_type }}">{{ auth_type.auth_type }}</option>
                        {% endfor %}
                  </select>
              </div>
        </div>
        <div class="layui-form-item">
              <label for="login_user" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>用户
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="login_user6" name="login_user6" required="" lay-verify="login_user" value="root"
                  autocomplete="off" class="layui-input">
              </div>
        </div>
        <div class="layui-form-item">
              <label for="password" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="password6" name="password6" required="" lay-verify="password" value=""
                  autocomplete="off" class="layui-input">
              </div>
        </div>
        <button class="layui-btn" onclick="LstartAll()">开始限开</button>
        <button class="layui-btn" onclick="add_hide_i6()">取消</button>
    </div>
    <!-- 弹出框部分end i6-->

    <!-- 弹出框部分start i7 -->
    <div id="i7" class="hide">
        <div style="padding-top: 30px;color: green;font-size: 20px;padding-bottom: 20px;">
            <span>批量启动操作</span>
        </div>
        <div class="layui-form-item">
              <label for="auth_type" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>选择执行认证方式
              </label>
              <div class="layui-input-inline">
                  <select id="auth_type7" name="auth_type7" style="height: 38px">
                        {% for auth_type in auth_type_list %}
                            <option value="{{ auth_type.auth_type }}">{{ auth_type.auth_type }}</option>
                        {% endfor %}
                  </select>
              </div>
        </div>
        <div class="layui-form-item">
              <label for="login_user" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>用户
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="login_user7" name="login_user7" required="" lay-verify="login_user" value="root"
                  autocomplete="off" class="layui-input">
              </div>
        </div>
        <div class="layui-form-item">
              <label for="password" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="password7" name="password7" required="" lay-verify="password" value=""
                  autocomplete="off" class="layui-input">
              </div>
        </div>
        <button class="layui-btn" onclick="StartAll()">开始启动</button>
        <button class="layui-btn" onclick="add_hide_i7()">取消</button>
    </div>
    <!-- 弹出框部分end i7-->

    <!-- 弹出框部分start i8 -->
    <div id="i8" class="hide">
        <div style="padding-top: 30px;color: green;font-size: 20px;padding-bottom: 20px;">
            <span>批量清档操作</span>
        </div>
        <div class="layui-form-item">
              <label for="auth_type" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>选择执行认证方式
              </label>
              <div class="layui-input-inline">
                  <select id="auth_type8" name="auth_type8" style="height: 38px">
                        {% for auth_type in auth_type_list %}
                            <option value="{{ auth_type.auth_type }}">{{ auth_type.auth_type }}</option>
                        {% endfor %}
                  </select>
              </div>
        </div>
        <div class="layui-form-item">
              <label for="login_user" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>用户
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="login_user8" name="login_user8" required="" lay-verify="login_user" value="root"
                  autocomplete="off" class="layui-input">
              </div>
        </div>
        <div class="layui-form-item">
              <label for="password" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="password8" name="password8" required="" lay-verify="password" value=""
                  autocomplete="off" class="layui-input">
              </div>
        </div>
        <button class="layui-btn" onclick="ClearAll()">开始清档</button>
        <button class="layui-btn" onclick="add_hide_i8()">取消</button>
    </div>
    <!-- 弹出框部分end i8-->

    <!-- 弹出框部分start i9 -->
    <div id="i9" class="hide">
        <div style="padding-top: 30px;color: green;font-size: 20px;padding-bottom: 20px;">
            <span>一键更新包括：备份，更新，停服，开服流程<span style="font-size: 8px;color: red">【注意：在没有配置文件变更下可使用此功能】</span></span>
        </div>
        <div class="layui-form-item">
              <label for="version_package" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>选择更新包
              </label>
              <div class="layui-input-inline" style="width: 480px;">
                  <select id="version_package9" name="version_package9" style="height: 38px">
                        {% for version_package in version_list %}
                            <option value="{{ version_package }}">{{ version_package }}</option>
                        {% endfor %}
                  </select>
              </div>
        </div>
        <div class="layui-form-item">
              <label for="parameter" class="layui-form-label" style="width: 120px">
                  单机并发线程
              </label>
              <div class="layui-input-inline" style="width: 520px;">
                  <input class="layui-input" id="max_threads9" name="max_threads9" type="number"
                  autocomplete="off" class="layui-input" placeholder="单机并发线程，默认为 5" value=5>
              </div>
        </div>
        <button class="layui-btn" onclick="OneclickUpdate()">开始一键更新</button>
        <button class="layui-btn" onclick="add_hide_i9()">取消</button>
    </div>
    <!-- 弹出框部分end i9-->

    <!-- 弹出框部分start i10 -->
    <div id="i10" class="hide">
        <div style="padding-top: 30px;color: green;font-size: 20px;padding-bottom: 20px;">
            <span>选中服配置连接对应跨服，生成配置文件到配置中心</span>
        </div>
        <div class="layui-form-item">
              <label for="cross_server_id10" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>选择连接的跨服
              </label>
              <div class="layui-input-inline" style="width: 480px;">
                  <select id="cross_server_id10" name="cross_server_id10" style="height: 38px">
                        {% for cross_server in cross_server_list %}
                            <option value="{{ cross_server.server_id }}">{{ cross_server.server_id }} - {{ cross_server.server_name }} - {{ cross_server.server_dir }}</option>
                        {% endfor %}
                  </select>
              </div>
        </div>
        <button class="layui-btn" onclick="ConnectCross()">配置跨服连接</button>
        <button class="layui-btn" onclick="add_hide_i10()">取消</button>
    </div>
    <!-- 弹出框部分end i10-->

    <!-- 弹出框部分start i11 -->
    <div id="i11" class="hide">
        <div style="padding-top: 30px;color: green;font-size: 20px;padding-bottom: 20px;">
            <span>批量操作选中服务器</span>
        </div>

        <div class="layui-form-item">
            <label for="execution_script_type" class="layui-form-label" style="width: 120px">
                <span class="x-red">*</span>执行任务类型
            </label>
            <div class="layui-input-inline" style="width: 520px;">
                <select id="execution_script_type" name="execution_script_type" style="height: 38px;">
                    {% for execution_script_type in script_type_list %}
                        <option value="{{ execution_script_type.script_name }}">{{ execution_script_type.script_name }} --> {{ execution_script_type.script_name_en }}</option>
                    {% endfor %}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
              <label for="parameter" class="layui-form-label" style="width: 120px">
                  脚本参数
              </label>
              <div class="layui-input-inline" style="width: 520px;">
                  <input class="layui-input" id="parameter" name="parameter"
                  autocomplete="off" class="layui-input" placeholder="参数1 参数2 ... 若不需要传参数，留空即可">
              </div>
        </div>

        <div class="layui-form-item">
              <label for="parameter" class="layui-form-label" style="width: 120px">
                  单机并发线程
              </label>
              <div class="layui-input-inline" style="width: 520px;">
                  <input class="layui-input" id="max_threads" name="max_threads" type="number"
                  autocomplete="off" class="layui-input" placeholder="单机并发线程，默认为 5" value=5>
              </div>
        </div>

        <hr>
        <div class="layui-form-item">
              <label for="auth_type" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>选择执行认证方式
              </label>
              <div class="layui-input-inline">
                  <select id="auth_type11" name="auth_type11" style="height: 38px">
                        {% for auth_type in auth_type_list %}
                            <option value="{{ auth_type.auth_type }}">{{ auth_type.auth_type }}</option>
                        {% endfor %}
                  </select>
              </div>
        </div>
        <div class="layui-form-item">
              <label for="login_user" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>用户
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="login_user11" name="login_user11" required="" lay-verify="login_user" value="root"
                  autocomplete="off" class="layui-input">
              </div>
       </div>
        <div class="layui-form-item">
              <label for="password" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="password11" name="password11" required="" lay-verify="password" value=""
                  autocomplete="off" class="layui-input">
              </div>
       </div>
        <button class="layui-btn" onclick="OpsAll()">开始执行</button>
        <button class="layui-btn" onclick="add_hide_i11()">取消</button>
    </div>
    <!-- 弹出框部分end i11-->


      <table class="layui-table" id='table1'>
        <thead>
          <tr>
            <th>
            <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>server_id</th>
            <th>服务器名称</th>
            <th>目录名称</th>
{#            <th>域名</th>#}
            <th>server_ip</th>
{#            <th>所属项目</th>#}
{#            <th>ssh端口</th>#}
            <th>定时任务状态</th>
            <th>清档状态</th>
            <th>备注</th>
            <th>创建时间</th>
            <th>操作</th>
            <th>编辑</th>
          </tr>
        </thead>
        <tbody>
            {% for game in game_list %}
              <tr>
                <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{{ game.server_id }}'><i class="layui-icon">&#xe605;</i></div>
                </td>
                <td>{{ game.server_id }}</td>
                <td>{{ game.server_name }}</td>
                <td>{{ game.server_dir }}</td>
                <td>{{ game.server_ip }}</td>
{#                <td>{{ game.b_project }}</td>#}
{#                <td>{{ game.ssh_port }}</td>#}
                {% if game.timing_task_status == 2 %}
                    <td style="color: yellowgreen;">{{ game.get_timing_task_status_display }}-<button style="color: #0e90d2;border: 0;" onclick="x_admin_show('定时任务状态详情','/super_cmdb/timing_task_detail-{{ game.server_id }}/',1200,700)">详情</button></td>
                {% elif game.timing_task_status == 3 %}
                    <td style="color: green;">{{ game.get_timing_task_status_display }}-<button style="color: #0e90d2;border: 0;" onclick="x_admin_show('定时任务状态详情','/super_cmdb/timing_task_detail-{{ game.server_id }}/',1200,700)">详情</button></td>
                {% elif game.timing_task_status == 4 %}
                    <td style="color: red;">{{ game.get_timing_task_status_display }}-<button style="color: #0e90d2;border: 0;" onclick="x_admin_show('定时任务状态详情','/super_cmdb/timing_task_detail-{{ game.server_id }}/',1200,700)">详情</button></td>
                {% elif game.timing_task_status == 5 %}
                    <td style="color: chartreuse;">{{ game.get_timing_task_status_display }}-<button style="color: #0e90d2;border: 0;" onclick="x_admin_show('定时任务状态详情','/super_cmdb/timing_task_detail-{{ game.server_id }}/',1200,700)">详情</button></td>
                {% else %}
                    <td>{{ game.get_timing_task_status_display }}-<button style="color: #0e90d2;border: 0;" onclick="x_admin_show('定时任务状态详情','/super_cmdb/timing_task_detail-{{ game.server_id }}/',1200,700)">详情</button></td>
                {% endif %}
                {% if game.timing_task_status == 5 %}
                    <td style="color: chartreuse;">{{ game.get_timing_task_status_display }} {{ game.clean_time }}</td>
                {% elif game.clean_status == "True" %}
                    <td style="color: green;">已清档 {{ game.clean_time }}</td>
                {% elif game.clean_status == "False" %}
                    <td>未清档 {{ game.clean_time }}</td>
                {% endif %}
                <td>{{ game.remarks }}</td>
                <td>{{ game.create_time|date:"Y-m-d H:i:s" }}</td>

                <td class="td-manage">
                    <button class="layui-btn layui-btn layui-btn-xs" style="background-color: #9166bb;" onclick="x_admin_show('配置定时任务','/super_cmdb/setting_timing_task-{{ game.server_id }}/',1000,700)"><i class="iconfont">&#xe6bb;</i> 配置定时任务</button>
{#                    <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('查看login日志','/super_cmdb/look_login_log-{{ game.server_id }}/',1500,600)" ><i class="layui-icon" style="width: 600px">&#xe6af;</i>login日志</button>#}
{#                    <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('查看gg日志','/super_cmdb/look_gg_log-{{ game.server_id }}/')" ><i class="layui-icon">&#xe6af;</i>gg日志</button>#}
{#                    <button id="restart_gg_d" class="layui-btn-danger layui-btn layui-btn-xs" style="background-color: #a29a30" onclick="restart_gg(this,'{{ game.server_id }}')" href="javascript:;" ><i class="layui-icon">&#xe6af;</i>重启gg</button>#}
{#                    <button class="layui-btn-danger layui-btn layui-btn-xs" style="background-color: #009688" onclick="restart_login(this,'{{ game.server_id }}')" href="javascript:;" ><i class="layui-icon">&#xe6af;</i>重启login</button>#}
{#                    <button class="layui-btn-danger layui-btn layui-btn-xs" style="background-color: #a29a30;" onclick="restart(this,'{{ game.server_id }}')" href="javascript:;" ><i class="layui-icon">&#xe6af;</i>重启game</button>#}
{#                    <button class="layui-btn-danger layui-btn layui-btn-xs" style="background-color: #009688" onclick="backup_mongodb(this,'{{ game.server_id }}')" href="javascript:;" ><i class="layui-icon">&#xe6af;</i>备份mongodb</button>#}
                    <button id="btn" class="layui-btn-danger layui-btn layui-btn-xs"  onclick="clean_game(this,'{{ game.server_id }}')" href="javascript:;" ><i class="layui-icon">&#xe69c;</i>游戏清档</button>
{#                    <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="del_game(this,'{{ game.server_id }}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>#}
                </td>
                <td class="td-manage">
                    <a title="编辑"  onclick="x_admin_show('编辑','/super_cmdb/gameserver_edit-{{ game.id }}',700,450)" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                  </a>
                </td>
              </tr>
            {% endfor %}
        </tbody>
      </table>

        <div class="page">
            {% for page_str in page_list %}
                {{ page_str|safe }}
            {% endfor %}
        </div>

    </div>
    <script type="text/javascript" src="/static/super_cmdb/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/super_cmdb/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/super_cmdb/js/xadmin.js"></script>
    <script src="/static/super_cmdb/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/static/super_cmdb/js/jquery.cookie.js"></script>
    <script>

        //表格选中着色
        var trs = document.getElementById('table1').getElementsByTagName('tr');
        window.onload = function(){
            for( var i=0; i<trs.length; i++ ){
                trs[i].onmousedown = function(){
                    tronmousedown(this);
                }
            }
        };
        function tronmousedown(obj){
            for( var o=0; o<trs.length; o++ ){
                if( trs[o] == obj ){
                    trs[o].style.backgroundColor = 'rgb(174, 212, 234)';
                }
                else{
                    trs[o].style.backgroundColor = '';
                }
            }
        }

        //去除遮罩层i3
        function remove_hide_i3() {
        document.getElementById("i2").classList.remove("hide");
        document.getElementById("i3").classList.remove("hide");
        }
        //添加遮罩层i3
        function add_hide_i3() {
            document.getElementById("i2").classList.add("hide");
            document.getElementById("i3").classList.add("hide");
        }

        //去除遮罩层i4
        function remove_hide_i4() {
        document.getElementById("i2").classList.remove("hide");
        document.getElementById("i4").classList.remove("hide");
        }
        //添加遮罩层i4
        function add_hide_i4() {
            document.getElementById("i2").classList.add("hide");
            document.getElementById("i4").classList.add("hide");
        }

        //去除遮罩层i5
        function remove_hide_i5() {
        document.getElementById("i2").classList.remove("hide");
        document.getElementById("i5").classList.remove("hide");
        }
        //添加遮罩层i5
        function add_hide_i5() {
            document.getElementById("i2").classList.add("hide");
            document.getElementById("i5").classList.add("hide");
        }

        //去除遮罩层i6
        function remove_hide_i6() {
        document.getElementById("i2").classList.remove("hide");
        document.getElementById("i6").classList.remove("hide");
        }
        //添加遮罩层i6
        function add_hide_i6() {
            document.getElementById("i2").classList.add("hide");
            document.getElementById("i6").classList.add("hide");
        }

        //去除遮罩层i7
        function remove_hide_i7() {
        document.getElementById("i2").classList.remove("hide");
        document.getElementById("i7").classList.remove("hide");
        }
        //添加遮罩层i7
        function add_hide_i7() {
            document.getElementById("i2").classList.add("hide");
            document.getElementById("i7").classList.add("hide");
        }

        //去除遮罩层i8
        function remove_hide_i8() {
        document.getElementById("i2").classList.remove("hide");
        document.getElementById("i8").classList.remove("hide");
        }
        //添加遮罩层i8
        function add_hide_i8() {
            document.getElementById("i2").classList.add("hide");
            document.getElementById("i8").classList.add("hide");
        }

        //去除遮罩层i9
        function remove_hide_i9() {
        document.getElementById("i2").classList.remove("hide");
        document.getElementById("i9").classList.remove("hide");
        }
        //添加遮罩层i9
        function add_hide_i9() {
            document.getElementById("i2").classList.add("hide");
            document.getElementById("i9").classList.add("hide");
        }

        //去除遮罩层i10
        function remove_hide_i10() {
        document.getElementById("i2").classList.remove("hide");
        document.getElementById("i10").classList.remove("hide");
        }
        //添加遮罩层i10
        function add_hide_i10() {
            document.getElementById("i2").classList.add("hide");
            document.getElementById("i10").classList.add("hide");
        }

        //去除遮罩层i11
        function remove_hide_i11() {
        document.getElementById("i2").classList.remove("hide");
        document.getElementById("i11").classList.remove("hide");
        }
        //添加遮罩层i11
        function add_hide_i11() {
            document.getElementById("i2").classList.add("hide");
            document.getElementById("i11").classList.add("hide");
        }

        //添加csrftoken
        $(function () {
            $.ajaxSetup({
                beforeSend:function (xhr,settings) {
                    xhr.setRequestHeader("X-CSRFtoken",$.cookie("csrftoken"));
                }
            })
        });

        //分页
        $(function () {
           var v = $.cookie("per_page_count");
           console.log(v)
           $("#pg").val(v);
        });
        function changePageSize(ths) {
            var current_page = $(ths).val();
            console.log(current_page);
            $.cookie("per_page_count", current_page);
            location.reload();
        }


          layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
              elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
              elem: '#end' //指定元素
            });
          });

          /*查看100行登陆日志*/
          function search_login_log(obj,id){
              layer.confirm('确认要重启gg吗？'+id,function(index){
                  //发异步删除数据
                  $.ajax({
                        url: "/super_cmdb/game_ops/",
                        type: "POST",
                        data: {"server_id":id,"ops_type":"restart_gg"},
                        success: function (msg) {
                            layer.msg(msg,{icon:1,time:6000});
                        }
                    });
              });
          }

          /*重启gg*/
          function restart_gg(obj,id){
              $("#restart_gg_d").attr("disabled", true); //点击按钮后使按钮暂时失效
              layer.confirm('确认要重启gg吗？'+id,function(index){
                  //发异步删除数据
                  $.ajax({
                        url: "/super_cmdb/game_ops/",
                        type: "POST",
                        data: {"server_id":id,"ops_type":"restart_gg"},
                        success: function (msg) {
                            layer.msg(msg,{icon:1,time:6000});
                        }
                    });
              });
          }
          /*重启login*/
          function restart_login(obj,id){
              layer.confirm('确认要重启登陆程序吗？'+id,function(index){
                  //发异步删除数据
                  $.ajax({
                        url: "/super_cmdb/game_ops/",
                        type: "POST",
                        data: {"server_id":id,"ops_type":"restart_login"},
                        success: function (msg) {
                            layer.msg(msg,{icon:1,time:60000});
                        }
                    });
              });
          }
          /*重启game*/
          function restart(obj,id){
              layer.confirm('确认要重启游戏吗？'+id,function(index){
                  //发异步删除数据
                  $.ajax({
                        url: "/super_cmdb/game_ops/",
                        type: "POST",
                        data: {"server_id":id,"ops_type":"restart"},
                        success: function (msg) {
                            layer.msg(msg,{icon:1,time:6000});
                        }
                    });
              });
          }
          /*备份mongodb*/
          function backup_mongodb(obj,id){
              layer.confirm('确认要备份数据吗？'+id,function(index){
                  //发异步删除数据
                  $.ajax({
                        url: "/super_cmdb/game_ops/",
                        type: "POST",
                        data: {"server_id":id,"ops_type":"backup_mongodb"},
                        success: function (msg) {
                            layer.msg(msg,{icon:1,time:6000});
                        }
                    });
              });
          }
          /*清档游戏*/
          function clean_game(obj,id){
              $("#btn").attr("disabled", true); //点击按钮后使按钮暂时失效
              layer.confirm('确认要清档游戏吗？'+id,function(index){
                  //发异步删除数据
                  layer.msg("清档中，请等待..或到任务管理中查看任务状态",{icon:1,time:80000});
                  $.ajax({
                        url: "/super_cmdb/game_ops/",
                        type: "POST",
                        data: {"server_id":id,"ops_type":"clear"},
                        success: function (msg) {
                            if (msg == "清档失败，该游戏服已经清档过，若需要再次清档，请先修改清档状态" ){
                                layer.msg(msg + id,{icon:3,time:80000});
                            } else {
                                layer.msg(msg + id,{icon:1,time:80000});
                            }
                        }
                    });
              });
              $("#btn").attr("disabled", false); //使按钮暂时生效
          }

          /*用户-删除*/
          function del_game(obj,id){
              layer.confirm('确认要删除吗？'+id,function(index){
                  //发异步删除数据
                  var url = "/super_cmdb/game_ops/";
                  //console.log(url);
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {"server_id":id,"ops_type":"del_game"},
                        success: function (msg) {
                            layer.msg(msg,{icon:1,time:6000});
                        }
                    });
              });
          }

          function delAll (argument) {

            var data = tableCheck.getData();

            layer.confirm('确认要删除选中项吗？'+data,function(index){
                //捉到所有被选中的，发异步进行删除
                var url = "/super_cmdb/gameserver_del/";
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {"gameserver_id":JSON.stringify(data)}, //将data转换成字符串才能提交到后端
                        success: function (data) {
                            //console.log(data);
                        }
                    });
                layer.msg('删除成功', {icon: 1});
                $(".layui-form-checked").not('.header').parents('tr').remove();
            });
          }

          function OpsAll (argument) {

            var data = tableCheck.getData();
            if (data == "") {
                alert("未选择需要操作的游戏服");
                return false;
            }
            var url = "/super_cmdb/gameserver_ops/";
            var execution_script_type = $("#execution_script_type").val();
            var parameter = $("#parameter").val();
            var max_threads = $("#max_threads").val();
            var auth_type = $("#auth_type11").val();
            var login_user = $("#login_user11").val();
            var password = $("#password11").val();
            if (password == "") {
                alert("请输入密码");
                return false;
            }

            layer.confirm('确认要操作选中的游戏服吗？'+data,function(index){
                //捉到所有被选中的，发异步进行操作
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {
                            "gameserver_id": JSON.stringify(data),
                            "execution_script_type": execution_script_type,
                            "parameter": parameter,
                            "max_threads": max_threads,
                            "auth_type": auth_type,
                            "login_user": login_user,
                            "password": password
                        }, //将data转换成字符串才能提交到后端
                        success: function (data) {
                            //console.log(data);
                        }
                    });
                layer.msg('操作任务已建立，请到任务管理列表查看状态', {icon: 1});
            });
          }

          function StopAll (argument) {

            var data = tableCheck.getData();
            if (data == "") {
                alert("未选择需要操作的游戏服");
                return false;
            }
            var url = "/super_cmdb/gameserver_stop/";
            var auth_type = $("#auth_type3").val();
            var login_user = $("#login_user3").val();
            var password = $("#password3").val();
            if (password == "") {
                alert("请输入密码");
                return false;
            }

            layer.confirm('确认要停止选中的游戏服吗？'+data,function(index){
                //捉到所有被选中的，发异步进行操作
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {
                            "gameserver_id":JSON.stringify(data),
                            "auth_type": auth_type,
                            "login_user": login_user,
                            "password": password
                        }, //将data转换成字符串才能提交到后端
                        success: function (data) {
                            //console.log(data);
                        }
                    });
                layer.msg('停服任务已建立，请到任务管理列表查看状态', {icon: 1});
            });
          }

          function BackupAll (argument) {

            var data = tableCheck.getData();
            if (data == "") {
                alert("未选择需要操作的游戏服");
                return false;
            }
            var url = "/super_cmdb/gameserver_backup/";
            var auth_type = $("#auth_type4").val();
            var login_user = $("#login_user4").val();
            var password = $("#password4").val();
            if (password == "") {
                alert("请输入密码");
                return false;
            }

            layer.confirm('确认要备份选中的游戏服吗？'+data,function(index){
                //捉到所有被选中的，发异步进行操作
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {
                            "gameserver_id":JSON.stringify(data),
                            "auth_type": auth_type,
                            "login_user": login_user,
                            "password": password
                        }, //将data转换成字符串才能提交到后端
                        success: function (data) {
                            //console.log(data);
                        }
                    });
                layer.msg('备份任务已建立，请到任务管理列表查看状态', {icon: 1});
            });
          }

          function UpdateAll (argument) {

            var data = tableCheck.getData();
            if (data == "") {
                alert("未选择需要操作的游戏服");
                return false;
            }
            var url = "/super_cmdb/gameserver_update/";
            var version_package = $("#version_package5").val();
            //var svn_version = $("#svn_version5").val();
            var auth_type = $("#auth_type5").val();
            var login_user = $("#login_user5").val();
            var password = $("#password5").val();
            if (password == "") {
                alert("请输入密码");
                return false;
            }
            if (version_package == "") {
                alert("请选择更新版本包");
                return false;
            }
            //if (svn_version == "") {
            //    alert("请输入校验版本号");
            //    return false;
            //}

            layer.confirm('确认要更新选中的游戏服吗？'+data,function(index){
                //捉到所有被选中的，发异步进行操作
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {
                            "gameserver_id": JSON.stringify(data),
                            "version_package": version_package,
                            //"svn_version": svn_version,
                            "auth_type": auth_type,
                            "login_user": login_user,
                            "password": password
                        }, //将data转换成字符串才能提交到后端
                        success: function (data) {
                            //console.log(data);
                        }
                    });
                layer.msg('更新任务已建立，请到任务管理列表查看状态', {icon: 1});
            });
          }

          function OneclickUpdate (argument) {

            var data = tableCheck.getData();
            if (data == "") {
                alert("未选择需要操作的游戏服");
                return false;
            }
            var url = "/super_cmdb/gameserver_oneclickupdate/";
            var version_package = $("#version_package9").val();
            var max_threads = $("#max_threads9").val();

            if (version_package == "") {
                alert("请选择更新版本包");
                return false;
            }

            layer.confirm('确认要一键更新选中的游戏服吗？'+data,function(index){
                //捉到所有被选中的，发异步进行操作
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {
                            "gameserver_id": JSON.stringify(data),
                            "version_package": version_package,
                            "max_threads": max_threads
                        }, //将data转换成字符串才能提交到后端
                        success: function (data) {
                            //console.log(data);
                        }
                    });
                layer.msg('更新任务已建立，请到任务管理列表查看状态', {icon: 1});
            });
          }

          function ConnectCross (argument) {

            var data = tableCheck.getData();
            if (data == "") {
                alert("未选择需要操作的游戏服");
                return false;
            }
            var url = "/super_cmdb/conf_setting_connectcross/";
            var cross_server_id = $("#cross_server_id10").val();
            if (cross_server_id == "") {
                alert("请选择需要连接的跨服");
                return false;
            }

            layer.confirm('确认要修改跨服配置吗？'+ data + "连接" + cross_server_id,function(index){
                //捉到所有被选中的，发异步进行操作
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {
                            "gameserver_id": JSON.stringify(data),
                            "cross_server_id": cross_server_id
                        }, //将data转换成字符串才能提交到后端
                        success: function (data) {
                            if (data.code == 0){
                                layer.alert(data.msg, {icon: 6});
                            } else {
                                layer.alert(data.msg, {icon: 7});
                            }
                        }
                    });
                return false;
            });
          }

          function LstartAll (argument) {

            var data = tableCheck.getData();
            if (data == "") {
                alert("未选择需要操作的游戏服");
                return false;
            }
            var url = "/super_cmdb/gameserver_lstart/";
            var auth_type = $("#auth_type6").val();
            var login_user = $("#login_user6").val();
            var password = $("#password6").val();
            if (password == "") {
                alert("请输入密码");
                return false;
            }

            layer.confirm('确认要限开选中的游戏服吗？'+data,function(index){
                //捉到所有被选中的，发异步进行操作
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {
                            "gameserver_id":JSON.stringify(data),
                            "auth_type": auth_type,
                            "login_user": login_user,
                            "password": password
                        }, //将data转换成字符串才能提交到后端
                        success: function (data) {
                            //console.log(data);
                        }
                    });
                layer.msg('限开任务已建立，请到任务管理列表查看状态', {icon: 1});
            });
          }

          function StartAll (argument) {

            var data = tableCheck.getData();
            if (data == "") {
                alert("未选择需要操作的游戏服");
                return false;
            }
            var url = "/super_cmdb/gameserver_start/";
            var auth_type = $("#auth_type7").val();
            var login_user = $("#login_user7").val();
            var password = $("#password7").val();
            if (password == "") {
                alert("请输入密码");
                return false;
            }

            layer.confirm('确认要启动选中的游戏服吗？'+data,function(index){
                //捉到所有被选中的，发异步进行操作
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {
                            "gameserver_id":JSON.stringify(data),
                            "auth_type": auth_type,
                            "login_user": login_user,
                            "password": password
                        }, //将data转换成字符串才能提交到后端
                        success: function (data) {
                            //console.log(data);
                        }
                    });
                layer.msg('启动任务已建立，请到任务管理列表查看状态', {icon: 1});
            });
          }

          function ClearAll (argument) {

            var data = tableCheck.getData();
            if (data == "") {
                alert("未选择需要操作的游戏服");
                return false;
            }
            var url = "/super_cmdb/gameserver_clear/";
            var auth_type = $("#auth_type8").val();
            var login_user = $("#login_user8").val();
            var password = $("#password8").val();
            if (password == "") {
                alert("请输入密码");
                return false;
            }

            layer.confirm('确认要清档选中的游戏服吗？'+data,function(index){
                //捉到所有被选中的，发异步进行操作
                  $.ajax({
                        url: url,
                        type: "POST",
                        //data: $('#layui-form').serialize(),
                        data: {
                            "gameserver_id":JSON.stringify(data),
                            "auth_type": auth_type,
                            "login_user": login_user,
                            "password": password
                        }, //将data转换成字符串才能提交到后端
                        success: function (data) {
                            //console.log(data);
                        }
                    });
                layer.msg('清档任务已建立，请到任务管理列表查看状态', {icon: 1});
            });
          }

        function submitForm(){
            //获取form表单对象,提交选择项目
            var form = document.getElementById("myform");
            form.submit();//form表单提交
        }
        function submitForm1(){
            //获取form表单对象,提交选择项目
            var form = document.getElementById("myform1");
            form.submit();//form表单提交
        }

        function submitForm_gameserver_filter(){
            //获取form表单对象,提交选择项目
            var form = document.getElementById("gameserver_filter");
            form.submit();//form表单提交
        }

        function exportCSV (argument) {
              var url = "/super_cmdb/export_CSV/";
              $.ajax({
                    url: url,
                    type: "POST",
                    data: {"post_ops": "exportCSV"},
                    beforeSend: function (xhr,settings) {
                        xhr.setRequestHeader("X-CSRFtoken",$.cookie("csrftoken"));
                        layer.msg('csv生成中,请等待......', {icon: 4,time:600000});
                    },
                    success: function (data) {
                        if (data.code == 0){
                            window.open("/static/super_cmdb/download/" + data.file_name);
                            layer.alert(data.msg, {icon: 6});
                        } else {
                            layer.alert(data.msg, {icon: 7});
                        }
                    }
              });
        }
    </script>
  </body>

</html>
